Skip to content

Conversation

@alexsku
Copy link
Owner

@alexsku alexsku commented Dec 24, 2016

The test illustrates how low the overhead of lock when there is no contention. This is a typical output of the test on my laptop:
Without locks took: 14.0863ms
With lock took: 39.8ms
With spinlock took: 29.7597ms
With concurrent queue took: 35.2681ms
With concurrent bag took: 156.2363ms
With concurrent dictionary took: 681.0128ms
With manual spinlock took: 19.2666ms

From these results it can be seen that using lock adds about 25 nanoseconds to the execution. which is only a little bit more than using Interlocked.CompareExchange (manual spinlock) test.

At the same time concurrent collections perform much worse when there is no contention.

{
var locked = false;
spinLock.Enter(ref locked);
if (!locked)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

never used SpinLock, i wonder when it is envisioned locked can be false?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants